package day2;
import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            Stack<Character> stack1 = new Stack<>();
            Stack<Character> stack2 = new Stack<>();
            int i = 0;
            while (i < str.length()) {
                while (i < str.length() && str.charAt(i) != ' ') {
                    stack1.push(str.charAt(i));
                    i++;
                }

                while (!stack1.empty()) {
                    stack2.push(stack1.pop());
                }
                if (i < str.length()) {
                    stack2.push(' ');
                    i++;
                }


            }
            StringBuilder str2 = new StringBuilder();
            while (!stack2.empty()) {
                str2.append(stack2.pop());
            }
            System.out.println(str2.toString());
        }
    }
    //逆置
    public static void reverse(char[] arr, int start, int end){
        while(start < end) {
            char tmp = arr[start];
            arr[start] = arr[end];
            arr[end] = tmp;
            start++;
            end--;
        }

    }
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            char[] ch = str.toCharArray();
            int len = ch.length;
            //整体进行逆置
            reverse(ch,0,len-1);
            int i = 0;
            while(i < len) {
                int j = i;
                while(j < len && ch[j] != ' ') {
                    j++;
                }
                if(j < len) {
                    reverse(ch,i,j-1);
                    i = j + 1;
                }else {
                    reverse(ch,i,j-1);
                    i = j;
                }
            }
            String str2 = new String(ch);
            System.out.println(str2);
        }

    }
}